#include<iostream>
#include<algorithm>

using namespace std;

const int N=1e5+10;

int a[N],b[N],tim[N],tran[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%d%d",&a[i],&b[i]);
			if(i) tran[i]=a[i]-b[i-1];
		}
		for(int i=0;i<n;i++) scanf("%d",&tim[i]);
		
		int time=a[0];
		if(n == 1)
		{
			time+=tran[0]+tim[0];
			printf("%d\n",time);
			continue;
		}
	//	int time=a[0];
		for(int i=0;i<n;i++)
		{
			time+=tran[i]+tim[i];
			if(i != n-1) time+=(b[i]-a[i]+1)/2;
			else break;
			if(time<b[i]) time=b[i];
		}
		printf("%d\n",time);
	}
	return 0;
}
